<template>

	<!-- 经销商信息维护 -->
	<div>
    <!-- 搜索 -->
    <TopFilter
      :list="topFilterInit"
      :cols="3"
      labelWidth="90"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter>
		<!-- table -->
		<FilterTable
			ref="table"
			:columns="columns"
			:isSelectColumn="isSelectColumn"
			:fetchapi="fetchApi"
			:params="fetchParams"
			:datakey="'records'"
			columnsRef='origin_originInfo_dealerFormChange_list_01'
			:onColumnsChange="columns => this.columns = columns"
		>
		</FilterTable>
	</div>
</template>
<script>
	// import commonSearch from '../commonSearch/index';
	import dealerFormChangeView from '../dealerFormChange/view';
	import { dictionary } from '@/utils/dictMixin';
	import { region } from '@/api/cms-common/region';//行政区域

	import { findDealerInfoChangeList } from '@/api/cms-api/origin/originInfo/OEM';
	import * as types from '@/api/cms-api/origin/originInfo/types';
	import { DICT_CODE } from '@/api/cms-api/origin/commonDealerType';		//经销商类型工具类

	export default {
		mixins: [dictionary,region],
		components: {
			dealerFormChangeView
		},
		props:{
			value: {
				type: Object,
				required: true
			},
		},
		data() {
			return {
				topFilterInit: this.topFilterInitFun(),
				isSelectColumn: false,
				visibleDrawerView:false,
				columns: this.creatHeader(),
				initData: {},
				fetchApi: findDealerInfoChangeList, //ipa 接口
				// fetchApi: this.falseApi, //ipa 接口
				// fetchParams: {queryByOrgCode:types.QUERY_BY_ORG_VALUE}, //参数
				fetchParams: {dealerAttachId:this.value.dealerAttachId} //参数
				// fetchParams: {}, //参数
			};
		},
		mounted() {
			this.BaseTable = this.$refs.table.$refs.pageTable;
		},
		methods: {
			//搜索字段
			topFilterInitFun() {
				return [ 
					{ type: 'INPUT', label: '变更项', fieldName: 'changeItem', placeholder: '请输入', initialValue: ''  },
					{ type: 'INPUT', label: '变更人', fieldName: 'changeUserName', placeholder: '请输入', initialValue: ''  },
					{ type: 'RANGE_DATE', label: '变更时间',fieldName: 'rangeDate',  dateType :"daterange" ,placeholder: '请选择', initialValue: ''}
				];
			},
			falseApi(){
				return {"resultCode":200,"errMsg":null,"elapsedMilliseconds":0,"data":{"records":[{"deptName":"大客户直销","passTime":null,"companyName":"测试","cityId":3822,"financeCompanyNames":"新能源","salesEmail":"123123@qq.com","maintenanceCategory":25871001,"salesLongitude":"","bank":"123","auditProposal":null,"dealerType":25381006,"salesLine":"1231","deptId":12,"salesAddress":"啊啊啊啊","registerAddress":"123123123","registerGov":"12312","billReceiveLinkman":"23123","auditTime":null,"roadTransportationLicense":"cs","brandId":null,"subType":null,"isPowerRecycing":null,"otherDesc":"","status":10031001,"constructType":25411001,"serviceLine":"","bankNum":"21321321321","billAddressee":"3123","dealerCode":"","ownerCode":"BJ","constructLevel":null,"sysManagerPhone":"15122524145","orgId":1,"serviceLongitude":"","taxpayerIdentityNumber":"1231321313","isDeleted":false,"joinTime":"2020-01-20T16:00:00.000+0000","isContainRAllowance":10041001,"serviceAddress":"xxx","inputAmount":null,"financePhone":"1231232","auditStatus":25511001,"equityRatio":null,"zipCode":"312321","emergencyContractPhone":"123123","officeName":"大客户直销","exaibitionRoomWidth":0.00,"officeArea":0.00,"dealerStatus":25521001,"applyId":null,"stationNum":0,"laborCoefficient":0.00,"officeId":26,"ownBrand":"","saleLevel":null,"emergencyContract":"1231231","hotLine":"","representative":"1231","updatedAt":"2020-02-20T08:25:35.000+0000","bankAccount":"123","companyCode":"BJ","servicesLatitude":"","dealerName":"测试","isRegionalAllowance":10041001,"batteryServiceStation":"0","dealerCompanyId":null,"shopLevel":25401001,"financeCompanyName":"新能源","businessTerm":"2020-02-13 00:00:00","equityRatio1":null,"serviceLevel":null,"equityRatio2":null,"provinceId":3791,"equityRatio3":null,"shareholderName":"","exaibitionRoomArean":0.00,"dealerShortname":"测试","cashDeposit":"50.00","invoicePhone":"123","billSendAddress":"1231","distanceBetweenSale":null,"establishmentDate":"2020-02-10T16:00:00.000+0000","systemManager":"张三","authTime":"2019-12-31T16:00:00.000+0000","isModelShop":null,"workshopArea":0.00,"designFee":0.00,"serviceEmail":"","inputAmount2":null,"inputAmount3":null,"constructStandard":null,"lsDealerCode":null,"dealerAttachId":991,"shareholderName2":"","ownerParCode":"BJ","districtId":3823,"shareholderName3":"","isCentrelAllowance":10041001,"shareholderName1":"","inputAmount1":null,"auditPerson":null,"allowanceFee":0.00,"salesLatitude":"","frontHotline":null}],"total":1,"size":20,"current":1,"searchCount":true,"pages":1},"success":true}
			},
			//搜索获取数据
			changeHandle(val) {				
				debugger
				if(val.rangeDate.length>0){
					val.startDate = val.rangeDate[0]
					val.endDate = val.rangeDate[1]
				}
				val.dealerAttachId = this.value.dealerAttachId;
				this.fetchParams = Object.assign({},val);
			},
			drawerHandle(row, type) {
				let id = -1;
				if(type != 'add'){
					id = row.dealerAttachId
				}
				this.initData = {
					type: type, //add/edit/show
					examineType:'show',//设置主表单内容为只读
					isExamine:false,//打开审核按钮和输入框
					formType:types.DEALER_INFO_FORM_STATUS_MAINTAIN_OEM,
					id: id  //表主键
				};
				if(type == 'show'){
					this.visibleDrawerView = true;
				}else{
					this.visibleDrawer = true;
				}
			},
			drawerClose(type) {
				this.visibleDrawer = false;
				this.visibleDrawerView = false;
				if (type === 'refresh') {
					// 重新加载
					this.fetchParams = { ...this.fetchParams };
				}
			},
			collapseHandle() {
				this.$nextTick(() => {
					this.BaseTable.EXECUTE_RESET_HEIGHT();
				});
			},
			//table表头和数据源
			creatHeader() {
				return [
					{ title: '序号', dataIndex: 'index', width: 80, sorter: true,
						render: props => {
							return <span>{props.row.index + 1}</span>;
						}
					},
					{ title: '变更项', dataIndex: 'changeItem', sorter: true },
					{ title: '变更前内容', dataIndex: 'contentBefore', sorter: true },
					{ title: '变更后内容', dataIndex: 'contentAfter', sorter: true },
					{ title: '变更人', dataIndex: 'changeUserName', sorter: true },
					{ title: '变更日期', dataIndex: 'changeDate', dateFormat: 'yyyy-MM-dd HH:mm:ss',sorter: true }
				];
			},
		},
	};
</script>

<style lang="less" scoped>
</style>
